﻿@model IEnumerable<IceTea.Domain.Models.TeamUser>

@using IceTea.Domain.Models;
@using IceTea.Domain;
@{
       Team team = ViewBag.Team;
}
<p class="text-info">
    @team.Description
</p>

<div class="col-md-12">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#teaminfotab1" data-toggle="tab">Team Members</a></li>
        <li><a href="#teaminfotab2" data-toggle="tab">Requests waiting for approving</a></li>
    </ul>

    <div class="tab-content">
        <div class="tab-pane fade in active" id="teaminfotab1">
        <table class="table">
            <thead><tr>
                <td class="col-md-3">User Name</td>
                <td class="col-md-5">Full Name</td>
                <td class="col-md-4">Title</td>
            </tr></thead>

            <tbody>
                <tr><td colspan="3"><h4><span class="label label-info">Product Owner</span></h4></td></tr>
                @foreach (TeamUser tu in Model)
                {
                    if (tu.State == (int)TeamUserState.Approved && tu.RoleId == (int)ScrumRole.ProductOwner)
                    {
                        <tr>
                            <td>@tu.Users.UserName</td>
                            <td>@tu.Users.FullName</td>
                            <td>@tu.Users.Title</td>
                        </tr>
                    }
                }

                <tr><td colspan="3"><h4><span class="label label-info">Scrum Master</span></h4></td></tr>
                @foreach (TeamUser tu in Model)
                {
                    if (tu.State == (int)TeamUserState.Approved && tu.RoleId == (int)ScrumRole.ScrumMaster)
                    {
                        <tr>
                            <td>@tu.Users.UserName</td>
                            <td>@tu.Users.FullName</td>
                            <td>@tu.Users.Title</td>
                        </tr>
                    }
                }

                <tr><td colspan="3"><h4><span class="label label-info">Development Team</span></h4></td></tr>
                @foreach (TeamUser tu in Model)
                {
                    if (tu.State == (int)TeamUserState.Approved && tu.RoleId == (int)ScrumRole.DevelopmentTeam)
                    {
                        <tr>
                            <td>@tu.Users.UserName</td>
                            <td>@tu.Users.FullName</td>
                            <td>@tu.Users.Title</td>
                        </tr>
                    }
                }
        
                <tr><td colspan="3"><h4><span class="label label-info">Stakeholder</span></h4></td></tr>
                @foreach (TeamUser tu in Model)
                {
                    if (tu.State == (int)TeamUserState.Approved && tu.RoleId == (int)ScrumRole.Stakeholder)
                    {
                        <tr>
                            <td>@tu.Users.UserName</td>
                            <td>@tu.Users.FullName</td>
                            <td>@tu.Users.Title</td>
                        </tr>
                    }
                }
            </tbody>
        </table>
        </div>
    
        <div class="tab-pane fade" id="teaminfotab2">
            <table class="table">
                <thead><tr>
                <td class="col-md-10"></td>
                <td class="col-md-2"></td>
                </tr></thead>
                <tbody>
                @foreach (TeamUser tu in Model)
                {
                    if (tu.State == (int)TeamUserState.Requested){
                    <tr>
                        <td>@(tu.Users.FullName) requested to join as @GetRoleName(tu.RoleId) at @(tu.CreatedTime.ToString())</td>
                        <td>@Ajax.ActionLink(" ", "DealJoinRequest", "Product",
                                    new AjaxOptions()
                                    {
                                        HttpMethod="Post",
                                        Url = Url.Action("DealJoinRequest", new { teamuserId = tu.Id, approve = true }),
                                        UpdateTargetId = "notifycontent",
                                        OnComplete="onDealComplete"
                                    }, new { @class="glyphicon glyphicon-ok", title="Approve"})
                            &nbsp;
                            @Ajax.ActionLink(" ", "DealJoinRequest", "Product",
                                    new AjaxOptions()
                                    {
                                        HttpMethod="Post",
                                        Url = Url.Action("DealJoinRequest", new { teamuserId = tu.Id, approve = false }),
                                        UpdateTargetId = "notifycontent",
                                        OnComplete="onDealComplete"
                                    }, new { @class="glyphicon glyphicon-remove", title="Deny"})                    
                        </td>
                    </tr>
                    }
                }
                </tbody>
            </table>
        </div>
    </div>
</div>

@helper GetRoleName(int roleId){
    if (roleId == (int)ScrumRole.ProductOwner){
        @:"Product Owner"
        }
    if (roleId == (int)ScrumRole.ScrumMaster){
       @:"Scrum Master"
       }
    if (roleId == (int)ScrumRole.DevelopmentTeam){
        @:"Development Team"
        }
    if (roleId == (int)ScrumRole.Stakeholder){
        @:"Stakeholder"
        }            
    }
